package com.uestc.soft.service;

import com.uestc.soft.mapper.MasterMapper;
import com.uestc.soft.pojo.Master;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MasterService {

    @Resource
    private MasterMapper masterMapper;

    public Master selectByMaster(Integer master) {   // 业务逻辑层
        return masterMapper.selectByMaster(master);
    }

    public Master selectByMasterAndDivide(Integer master, String divide) {
        return masterMapper.selectByMasterAndDivide(master, divide);
    }

    public Master selectByMasters(Master masters) {
        return masterMapper.selectByMasters(masters);
    }

    public Map<String, Object> selectByPage(int page, int limit, Integer master, String divide) {
        // page 页码   (page-1)*limit=起始下标index
        int index = (page - 1) * limit;   // 计算出起始下标
        List<Master> masterList = masterMapper.selectByPage(index, limit, master, divide);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", masterMapper.selectCount(master, divide));
        map.put("data", masterList);
        return map;
    }

    public Map<String, Object> insert(Master master) {

        masterMapper.insert(master);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "新增用户成功");
        return map;
    }

    public Map<String, Object> deleteByMaster(Integer master) {
        masterMapper.deleteByMaster(master);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "删除主机成功");
        return map;
    }

    public Map<String, Object> update(Integer master, String divide, Integer weakpassword, String LastLoginTime) {
        masterMapper.update(master, divide, weakpassword, LastLoginTime);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "更新主机成功");
        return map;
    }
}
